package com.ywl.designpattern.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * 3. 创建组合节点类
 * @author yuwl
 * @description 然后,我们创建表示目录的组合节点类:
 * @since 2024-07-03 10:45
 */
public class Directory implements FileSystemComponent{

    private String name;

    private List<FileSystemComponent> children = new ArrayList<>();

    public Directory(String name) {
        this.name = name;
    }

    @Override
    public void display() {
        System.out.println("Directory = " + name);
        for (FileSystemComponent child : children) {
            child.display();
        }
    }

    @Override
    public void add(FileSystemComponent component) {
        children.add(component);
    }

    @Override
    public void remove(FileSystemComponent component) {
        children.remove(component);
    }

    @Override
    public FileSystemComponent getChild(int i) {
        return children.get(i);
    }
}
